package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.pojo.NewStuDetail;
import com.ruoyi.system.pojo.StuDetail;
import com.ruoyi.system.pojo.StuList;
import com.ruoyi.system.service.StuTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class StuTaskController extends BaseController {
    @Autowired
    private StuTaskService stuTaskService;

    //学生列表界面 todo
    @GetMapping("/listJSP")
    public String listJSP(){
        return "/stuTask/StuList";
    }


    //学生列表的数据
    @GetMapping("/stuList")
    @ResponseBody
    public TableDataInfo stuList() {
        startPage();
        List<StuList> stuLists = stuTaskService.stuList();
        return getDataTable(stuLists);
    }

    // 新增学生页面 todo
    @PostMapping("/addJSP")
    public String addJSP(){
        return "/stuTask/StuAdd";
    }

    //新增学生界面接口
    @PostMapping("/addStu")
    @ResponseBody
    public AjaxResult addStu(NewStuDetail newStuDetail) {
        stuTaskService.addStu(newStuDetail);
        return AjaxResult.success();
    }

    //todo 编辑学生页面

    //编辑学生(通过学号获取信息)
    @GetMapping("/edit/{xh}")
    public String editStudent(@PathVariable Long xh, ModelMap modelMap) {
        StuDetail stuDetails = stuTaskService.findStudentByXh(xh);
        modelMap.put("xh", stuDetails.getXh());
        return "stu/edit";
    }

    //编辑学生(按钮)
    @PostMapping("/edit/task")
    @ResponseBody
    public AjaxResult update(StuDetail stuDetail) {
        stuTaskService.update(stuDetail);
        return AjaxResult.success();
    }

    //todo 学生详情表


    //返回详情数据（通过学号）
    @GetMapping("/stuDetail/{xh}")
    @ResponseBody
    public TableDataInfo stuDetail(@PathVariable Long xh) {
        startPage();
        List<StuDetail> stuDetails = stuTaskService.stuDetail(xh);
        return getDataTable(stuDetails);
    }

}
